package com.headhunter.company;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import com.headhunter.server.Company;
import com.headhunter.server.Graduate;

public class CompanyImpl extends UnicastRemoteObject implements Company {
	
	private static final long serialVersionUID = 1L;
	
	public CompanyImpl() throws RemoteException {
		super();
	}

	public boolean approveApplication(int companyNo, int applicationId, Graduate g) throws RemoteException {
		switch (companyNo) {
			case 1:
				return approveApplication1(applicationId, g);
			case 2:
				return approveApplication2(applicationId, g);
			case 3:
				return approveApplication3(applicationId, g);
			default:
				throw new RemoteException("No company exists with id " + companyNo);
		}
	}
	
	//TODO better algorithm should be used
	private boolean approveApplication1(int applicationId, Graduate g) {
		if (g.getAge() > 30) {
			return true;
		} else {
			return false;
		}
	}
	
	private boolean approveApplication2(int applicationId, Graduate g) {
		if (g.getGender().equals("female") && g.getQualifications().contains("C++")) {
			return true;
		} else {
			return false;
		}
	}

	private boolean approveApplication3(int applicationId, Graduate g) {
		if (g.getDegrees().contains("CS") && g.getQualifications().contains("FPGA")) {
			return true;
		} else {
			return false;
		}
	}
}